import sys
import matplotlib.pyplot as plt
import get_metric
plt.rcParams['font.sans-serif'] = ['Times New Roman']
plt.rcParams.update({"font.size":20})


if __name__ == "__main__":
    file_name = sys.argv[1]
    time_list, delay_list = get_metric.get_delay_list(file_name)

    time_list = [t - time_list[0] for t in time_list]

    # cut = 0
    # for i, time in enumerate(time_list):
    #     if time > 60:
    #         cut = i
    # #         break

    # time_list = time_list[0:cut]
    # delay_list = delay_list[0:cut]
    
    loss_time_list = get_metric.get_loss_list(file_name)
    loss_time_list = [t - loss_time_list[0] for t in loss_time_list]

    plt.figure(figsize=(6, 3))
    plt.plot(time_list, delay_list)
    
    for loss_time in loss_time_list:
        if loss_time <= time_list[-1]:
            plt.axvline(loss_time, color = 'r')
    
    plt.xlabel('Time (s)')
    plt.ylabel('Delay (s)')
    plt.grid()
    plt.tight_layout()
    file_name = __file__.split('/')[-1].split('.')[0]
    plt.savefig(f"{file_name}.png", bbox_inches='tight')
    # plt.show()
